﻿Public Class Datum
    Implements IComparable

    Private day, month, year As Integer
    Public Property Tag() As Integer
        Get
            Return day
        End Get
        Set(ByVal value As Integer)
            day = value
        End Set
    End Property
    Public Property Monat() As Integer
        Get
            Return month
        End Get
        Set(ByVal value As Integer)
            month = value
        End Set
    End Property
    Public Property Jahr() As Integer
        Get
            Return year
        End Get
        Set(ByVal value As Integer)
            year = value
        End Set
    End Property
    Public Overrides Function ToString() As String
        If Tag.ToString.Length = 1 AndAlso Monat.ToString.Length = 1 Then
            Return "0" + Tag.ToString + ".0" + Monat.ToString + "." + Jahr.ToString
        ElseIf Monat.ToString.Length = 1 Then
            Return Tag.ToString + ".0" + Monat.ToString + "." + Jahr.ToString
        ElseIf Tag.ToString.Length = 1 Then
            Return "0" + Tag.ToString + "." + Monat.ToString + "." + Jahr.ToString
        Else
            Return Tag.ToString + "." + Monat.ToString + "." + Jahr.ToString
        End If
    End Function

    Public Sub New(ByVal Day As Integer, ByVal month As Integer, ByVal year As Integer)
        Tag = Day
        Monat = month
        Jahr = year
    End Sub

    Public Sub New(ByVal Datum As String)
        'Dim int(3) As Integer
        Dim int As String() = Datum.Split(".")
        Tag = CInt(int(0))
        Monat = CInt(int(1))
        Jahr = CInt(int(2))
    End Sub

    Public Sub New(ByVal Datum As Date)
        Tag = Datum.Day
        Monat = Datum.Month
        Jahr = Datum.Year
    End Sub
    Public Sub New()

    End Sub

    Public Function GetCurrentDate() As Datum
        Dim datum As Date = Date.Today
        Dim rueckgabe As New Datum
        rueckgabe.day = datum.Day
        rueckgabe.Jahr = datum.Year
        rueckgabe.Monat = datum.Month

        Return rueckgabe
    End Function

    Public Shared Function Today() As String
        Return New Datum(Date.Today).ToString
    End Function

    Public Shared Function DateToString(ByVal datum As Date) As String
        Return New Datum(datum).ToString
    End Function

    Public Function CompareTo(obj As Object) As Integer Implements System.IComparable.CompareTo
        Dim datum As Datum = obj
        Dim dt1 As DateTime = New Date(Jahr, Monat, Tag)
        Dim dt2 As DateTime = New Date(datum.Jahr, datum.Monat, datum.Tag)
        If dt1.Year = dt2.Year Then
            If dt2.Month = dt1.Month Then
                Return dt1.Day - dt2.Day
            Else
                Return dt1.Month - dt2.Month
            End If
        Else
            Return dt1.Year - dt2.Year
        End If
    End Function

    Public Overrides Function Equals(obj As Object) As Boolean
        Try
            Dim date2 As Datum = obj
            If date2.Tag = Tag AndAlso date2.Monat = Monat AndAlso date2.Jahr = Jahr Then
                Return True
            End If
        Catch ex As Exception : End Try
        Return False
    End Function

    Public Function ToDate() As Date
        Return New Date(Jahr, Monat, Tag)
    End Function
End Class

Public Enum Monat
    Januar = 1
    Februar = 2
    März = 3
    April = 4
    Mai = 5
    Juni = 6
    Juli = 7
    August = 8
    September = 9
    Oktober = 10
    November = 11
    Dezember = 12
End Enum
